package com.k8.common.aop.internal.interceptor;

import com.k8.common.aop.internal.advice.AdviceOrderEnum;
import com.k8.common.aop.internal.advice.AfterReturningAdvice;
import com.k8.common.aop.internal.invocation.MethodInvocation;
import com.k8.common.util.AopUtil;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class AfterReturningMethodInterceptor extends ProxyMethodExecutor implements AfterReturningAdvice {
    public AfterReturningMethodInterceptor(Object target, Method targetMethod) {
        super(target, targetMethod);
    }

    @Override
    public int getAdviceOrder() {
        return AfterReturningAdvice.super.getAdviceOrder();
    }

    @Override
    boolean judgeArgument(Parameter parameter, Method targetMethod) {
        return AopUtil.judgeJoinAdviceArgs(parameter, AdviceOrderEnum.AfterReturning,targetMethod);
    }

    @Override
    Object invoke0(MethodInvocation invocation) throws Throwable {
        Object result = invocation.proceed();
        invokeAdvice(result);
        return result;
    }
}
